package com.xuwang.controller;

import com.xuwang.pojo.CompanyStaff;
import com.xuwang.service.impl.CompanyStaffServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 企业从业人员基本信息表(CompanyStaff)表控制层
 *
 * @author yuepeng
 * @since 2021-09-15 09:23:04
 * @version 1.0
 */
@RestController
@RequestMapping("/companyStaff")
@Api(value = "企业从业人员基本信息表(CompanyStaff)管理",tags = "企业从业人员基本信息表(CompanyStaff)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class CompanyStaffController {
    /**
     * 服务对象
     */
    @Resource
    private CompanyStaffServiceImpl companyStaffServiceImpl;

    /**
     * 分页查询数据
     * @param companyName 企业名
     * @param staffName 员工名
     * @param sex 性别
     * @param healthCondition 健康状况
     * @param trainCondition 培训状况
     * @param index  需要查询的页码
     * @param limit  每页条数
     * @return 多条数据
     */
    @RequestMapping(value = "/selectForPage", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyName", value = "企业名", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "staffName", value = "员工名", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "sex", value = "性别", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "healthCondition", value = "健康状况", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "trainCondition", value = "培训状况", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", paramType = "query", dataType = "String", required = true),
    })
    public Map<String, Object> selectForPage(String companyName,
                                             String staffName,
                                             String sex,
                                             String healthCondition ,
                                             String trainCondition,
                                             @RequestParam("page") int index,
                                             @RequestParam("limit") int limit) {
        return this.companyStaffServiceImpl.selectForPage(companyName, staffName, sex, healthCondition, trainCondition, index, limit);
    }
    
    /**
     * 查询所有数据
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有数据接口",notes = "查询所有数据接口",httpMethod = "GET")
    public Map<String, Object> selectAll() {
        return this.companyStaffServiceImpl.selectAll();
    }
    
    /**
     * 通过主键删除多条数据
     *
     * @param id 主键
     * @return 多条数据
     */
    @Transactional
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    @ApiOperation(value = "根据一个主键删除多条记录的接口",notes = "根据一个主键删除多条记录的接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键集合（格式：1,2,3）",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> deleteById(@RequestParam("id") String id) {
        return this.companyStaffServiceImpl.deleteById(id);
    }
    
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    @ApiOperation(value = "通过主键查询一个企业从业人员基本信息的接口",notes = "通过主键查询一个企业从业人员基本信息的接口",httpMethod = "GET")
    public Map<String, Object> selectById(Integer id) {
        return this.companyStaffServiceImpl.selectById(id);
    }
    
    /**
     * 通过主键更新单条数据
     *
     * @param companyStaff 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @Transactional
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    @ApiOperation(value = "通过主键更新一个企业从业人员基本信息的接口",notes = "通过主键更新一个企业从业人员基本信息的接口",httpMethod = "POST")
    public Map<String, Object> updateById(@RequestBody @ApiParam(name = "companyStaff",value = "pojo模型",required = true) CompanyStaff companyStaff) {
        return this.companyStaffServiceImpl.updateById(companyStaff);
    }
    
    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param companyStaff 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @Transactional
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "根据完整记录新增一个企业从业人员基本信息的接口",notes = "根据完整记录新增一个企业从业人员基本信息的接口",httpMethod = "POST")
    public Map<String, Object> insert(@RequestBody @ApiParam(name = "companyStaff",value = "pojo模型",required = true) CompanyStaff companyStaff) {
        return this.companyStaffServiceImpl.insert(companyStaff);
    }

}
